/*
* @Author: Administrator
* @Date:   2016-11-22 13:47:59
* @Last Modified by:   Administrator
* @Last Modified time: 2016-11-22 13:58:55
*/

'use strict';

var marked = require('marked');
var renderer = new marked.Renderer();

renderer.heading = function (text, level) {
  var escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
/*toLowerCase() 方法用于把字符串转换为小写*/
/*replace() 方法用于在字符串中用一些字符替换另一些字符，或替换一个与正则表达式匹配的子串*/
  return '<h' + level + '><a name="' +
                escapedText +
                 '" class="anchor" href="#' +
                 escapedText +
                 '"><span class="header-link"></span></a>' +
                  text + '</h' + level + '>';
},

console.log(marked('# heading+', { renderer: renderer }));